//
//  CLPComponent.h
//  ComponentLinkDemo
//
//  Created by zhenby on 2017/2/22.
//  Copyright © 2017年 zhenby. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CLPComponentDataModel.h"
#import "CLPActionObserver.h"

@protocol CLPComponent<NSObject>


@optional
#pragma mark - Basic Property

@property (nonatomic, strong, nullable) NSString *componentID;

@property (nonatomic, weak, readonly, nullable) id<CLPComponent> supercomponent;

@property (nonatomic, strong, readonly, nonnull) NSArray<id<CLPComponent>> *subComponents;


#pragma mark - Data Model

@property (nonatomic, strong, nullable) id<CLPComponentDataModel> dataModel;

- (void)loadDataModel;



#pragma mark - Super & Sub Component

- (void)addSubcomponent:(nonnull id<CLPComponent>)subcomponent;

- (void)removeFromSupercomponent;

- (void)exchangeSubcomponentAtIndex:(NSInteger)index1
            withSubcomponentAtIndex:(NSInteger)index2;

- (void)insertSubcomponent:(nonnull id<CLPComponent>)subcomponent
         aboveSubcomponent:(nonnull id<CLPComponent>)siblingSubcomponent;

- (void)insertSubcomponent:(nonnull id<CLPComponent>)subcomponent
            belowComponent:(nonnull id<CLPComponent>)siblingSubcomponent;

- (void)bringSubcomponentToFront:(nonnull id<CLPComponent>)subcomponent;

- (void)sendSubcomponentToBack:(nonnull id<CLPComponent>)subcomponent;

- (nullable id<CLPComponent>)subcomponentWithComponentID:(nonnull NSString *)componentID;


#pragma mark - ActionPerformer
- (void)postActionEvent:(nonnull CLActionEvent *)action;

//获取服务事件
- (nullable NSDictionary*)performActionEvent:(nonnull CLActionEvent*)action;
//提供服务事件处理
- (nullable NSDictionary*)actionServiceWithEvent:(nonnull CLActionEvent*)action;

#pragma mark - Component Life

- (void)onComponentWillLoad;
- (void)onComponentDidLoad;
- (void)onComponentWillUnload;
- (void)onComponentDidUnLoad;

@end


